package cn.wanda.bi.sunshine.platform.server.aspect;

import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.wanda.bi.sunshine.platform.server.SunshineCode;
import cn.wanda.bi.sunshine.platform.server.bean.KeyCommon;
import cn.wanda.bi.sunshine.platform.server.client.wrapper.IMCClientWrapper;
import cn.wanda.bi.sunshine.platform.server.utils.PasswordUtil;
import cn.wanda.bi.sunshine.platform.server.utils.exception.SunshineException;

/**
 * Created by wangfupeng1 on 2017-5-6.
 */
@Aspect
@Component
public class AuthUserAspect {

    @Autowired
    private HttpServletRequest request;
    @Autowired
    private IMCClientWrapper imcClientWrapper;

    @Before("@annotation(cn.wanda.bi.sunshine.platform.server.aspect.AuthUser)")
    public void authUser(JoinPoint point) throws Throwable {
    	authUserIMC();
    }
    
    public void authUserIMC() {
    	String token = request.getHeader("token");
    	imcClientWrapper.v1AuthUserCheckToken(token);
    	String path = request.getMethod()+request.getServletPath();
    	imcClientWrapper.v1AuthUserAccessToken(token, path);
    }
    
}
